#include "stdafx.h"
#include "VSCtxMenuFixApp.h"

#define TRAY_ICON_ID 1

CMyTrayIcon::CMyTrayIcon(HWND hWnd)
{
    m_Success = FALSE;
    m_hWnd = hWnd;

    NOTIFYICONDATA nid;

    ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
    nid.cbSize = sizeof(NOTIFYICONDATA);

    nid.hWnd = m_hWnd;
    nid.uID = TRAY_ICON_ID;
    nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    nid.uCallbackMessage = WM_APP_TRAYCALLBACK;
    nid.hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_APP));
    lstrcpy(nid.szTip, CMyResources::GetAppTitle());

    if (!Shell_NotifyIcon(NIM_ADD, &nid))
    {
        return;
    }

    m_Success = TRUE;
}

CMyTrayIcon::~CMyTrayIcon()
{
    if (m_Success)
    {
        NOTIFYICONDATA nid;

        ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
        nid.cbSize = sizeof(NOTIFYICONDATA);

        nid.hWnd = m_hWnd;
        nid.uID = TRAY_ICON_ID;

        Shell_NotifyIcon(NIM_DELETE, &nid);
    }
}
